<template>
  <div class="child1">
    <h2>我是Child1</h2>
    <h4>弟弟给我的车：{{che}}</h4>
    <h4>GrandSon给我的牛奶：{{ niunai }}</h4>
  </div>
</template>

<script>
  export default {
    name:'Child1',
    data() {
      return {
        che:'',
        niunai:''
      }
    },
    methods: {
      saveCar(value){
        console.log('哥哥(Child1)收到了汽车：',value)
        this.che = value
      },
      saveMilk(value){
        console.log('Child1收到了牛奶：',value)
        this.niunai = value
      }
    },
    mounted() {
      // console.log('哥哥的输出',this.x)
      this.$bus.$on('get-car',this.saveCar)
      this.$bus.$on('get-milk',this.saveMilk)
    },
    beforeDestroy() {
      this.$bus.$off('get-car')
      this.$bus.$off('get-milk')
    },
  }
</script>

<style scoped>
  .child1 {
    background-color: skyblue;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
    margin-top: 10px;
  }
</style>